import Mock from 'mockjs'

const List = []
const count = 100

for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    code: '@integer(10000, 90000)',
    old_code: '@sentence(1, 1)',
    empty: '',
    workpiece_code: 'name',
    pch: '@sentence(1, 1)',
    cqs: '@integer(300, 5000)',
    'daily_finish|31': ['@integer(300, 5000)'],
    this_month: '@integer(300, 5000)',
    total_finish: '@integer(300, 5000)'
  }))
}

export default [
  {
    url: '/yuanche/list',
    type: 'get',
    response: config => {
      const { page = 1, limit = 20 , code} = config.query
      let mockList = List.filter(item => {
        if (code && item.code !== parseInt(code)) return false
        return true
      })

      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

      return {
        code: 20000,
        data: {
          total: mockList.length,
          items: pageList
        }
      }
    }
  }
]
